package cur.nature.admin.controller;

import cur.nature.admin.model.vo.Admin_AddressVO;
import cur.nature.admin.service.admin_AddressService;
import cur.nature.framework.mvc.base.BaseAPI;
import cur.nature.framework.mvc.crud.CrudController;
import cur.nature.tinyorm.core.bean.PageBean;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 用户信息 Controller
 * 作者：Auto Generator By wujian
 * 生成日期：2024-02-15 21:03:32
 */
@Tag(name = "用户地址 接口")
@RestController
@RequestMapping("admin/v1/api/Admin_Address")
public class Admin_AddressController extends CrudController<admin_AddressService> {
    public Admin_AddressController(admin_AddressService baseService) {
        super(baseService);
    }

    @Operation(summary = "查询 用户地址")
    @PostMapping("/list")
    public PageBean<Admin_AddressVO> list(@Valid @RequestBody Admin_AddressVO.list_Param param) throws Exception {
        PageBean<Admin_AddressVO> list = getService().list(param);
        return list;
    }

    @Operation(summary = "根据id查询用户地址")
    @PostMapping("/queryById")
    public Admin_AddressVO queryById(@Valid @RequestBody Admin_AddressVO.queryById_Param param) throws Exception {
        Admin_AddressVO vo = getService().queryById(param.getAddressId());
        return vo;
    }

    @Operation(summary = "根据用户id查询用户默认地址")
    @PostMapping("/getDefaultAddress")
    public Admin_AddressVO getDefaultAddress(@Valid @RequestBody Admin_AddressVO.getDefaultAddress_Param param) throws Exception {
        Admin_AddressVO vo = getService().getDefaultAddress(param);
        return vo;
    }

    @Operation(summary = "更新 用户地址")
    @PostMapping("/operate")
    public BaseAPI.SaveResult<Admin_AddressVO> save(@Valid @RequestBody List<Admin_AddressVO> param) throws Exception {
        int rows = getService().saveList(param);
        BaseAPI.SaveResult result = new BaseAPI.SaveResult();
        result.setRows(rows);
        result.setObject(rows == 0 ? null : param);
        return result;
    }

}

